package com.ludomancy.archeologyrpg;

import java.util.Properties;

import com.ludomancy.gamelib.DataStorage;
import com.ludomancy.gamelib.DialogWidget;
import com.ludomancy.gamelib.GameApplet;
import com.ludomancy.gamelib.GameCanvas;
import com.ludomancy.gamelib.Sound;
import com.ludomancy.gamelib.DialogWidget.DialogListener;

public class ArcheologyRPGApplet extends GameApplet implements DialogListener
{
	public static MainWidget mainWidget;
	public static ArcheologyRPGApplet app;
	
	public void init()
	{
		super.init(new GameTheme());
		app = this;
		
		// preloading
		Sound.soundActivated = true;
		
		// should we load a savegame?
		try
		{
//			Properties props = DataStorage.load("starwave");
//			String levelString = (String)props.get("level");
		}
		catch(Exception e)
		{
		}
		resetGame(true, null);
	}
	
	public void resetGame(boolean showBriefing, int[][] initialSetup)
	{
		// create the game
		new Game();
		
		// create the UI
		gameCanvas.destroyWidget(mainWidget);
		mainWidget = new MainWidget(null, getBounds(), initialSetup, showBriefing);
		gameCanvas.showWidget(mainWidget);
		BriefingWidget intro = new BriefingWidget(mainWidget, "Crashing...crashing into this little planet that looked so promising.\nAnother archeology expedition gone awry. But this time there's no one to hear the call. We're left to our own resources...to survive.", "Start", this);
		GameCanvas.screen.showWidgetModal(intro);		

	}
	
	public void restart()
	{
		saveData();
		resetGame(true, null);
	}
	
	private void saveData()
	{
		// save level
		Properties props = new Properties();
		DataStorage.save("starwave", props);		
	}

	public void onDialogClosed(DialogWidget widget)
	{
	}
}
